package com.zy.controller;

import com.github.pagehelper.PageInfo;
import com.zy.entity.Branch;
import com.zy.entity.Department;
import com.zy.service.BranchService;
import com.zy.service.DepartmentService;
import com.zy.util.R;
import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping({"department"})
public class DepartmentController {

    @Resource
    DepartmentService departmentService;

    @GetMapping({"getById/{id}"})
    public R getById(@PathVariable Integer id) {
        Department branch = this.departmentService.getById(id);
        return R.ok().put("menu", branch);
    }

    @PutMapping({"save"})
    public R save(@RequestBody Department department) {
        this.departmentService.save(department);
        return R.ok();
    }

    @PostMapping({"updateById"})
    public R updateById(@RequestBody Department department) {
        this.departmentService.updateById(department);
        return R.ok();
    }

    @PostMapping({"status/{id}"})
    public R status(@PathVariable Integer id) {
        this.departmentService.status(id);
        return R.ok();
    }

    @PostMapping({"page/{page}/{limit}"})
    public R tree(@RequestBody Department department, @PathVariable Integer page, @PathVariable Integer limit) {
        PageInfo<Department> pageInfo = this.departmentService.page(department, page, limit);
        return R.ok().put("pageInfo", pageInfo);
    }

    @DeleteMapping({"delete/{id}"})
    public R delete(@PathVariable Integer id) {
        this.departmentService.delete(id);
        return R.ok();
    }

}
